package com.hk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hk.mapper.INavMapper;
import com.hk.model.Nav;
import com.hk.service.INavService;
import com.hk.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/21 14:22
 * @Statement: 导航栏Service层接口实现类
 */
@Service
public class NavServiceImpl implements INavService {

    @Autowired
    INavMapper iNavMapper;

    @Override
    public List<Nav> findAll(Integer page, Integer limit, Nav t) {
//        PageHelper.startPage(page,limit);
        List<Nav> contactUsList = iNavMapper.findAll(t);
        return contactUsList;
    }

    @Override
    public int count(Integer page, Integer limit, Nav t) {
//        PageHelper.startPage(page,limit);
        int count = iNavMapper.count(t);
        return count;
    }

    @Override
    public Nav findById(Integer id) {
        Nav nav = iNavMapper.findById(id);
        return nav;
    }

    @Override
    public int save(Nav t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtCreate(dateTimeString);
        t.setGmtModified(dateTimeString);
        int save = iNavMapper.save(t);
        if (save == 1) {
            System.out.println("导航信息添加成功！");
        }
        return save;
    }

    @Override
    public int update(Nav t) {
        //        修改日期时间
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtModified(dateTimeString);
        int update = iNavMapper.update(t);
        if (update == 1) {
            System.out.println("当前导航信息修改成功");
        }
        return update;
    }

    @Override
    public int delete(Integer id) {
        int delete = iNavMapper.delete(id);
        if (delete == 1) {
            System.out.println("当前导航信息删除成功！");
        }
        return delete;
    }

}
